/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.ak.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ConfigurationUtils {
    private static final Logger logger 				= LoggerFactory.getLogger(ConfigurationUtils.class);
    public static final String CONFIG_FILE			= "/ak-frontend.properties";
    public static final String BASE_USER_API_URL	= get("environment.ak_user_api_url");
    public static Properties PROPERTIES = null;

    /**
     * Get configuration of this application.
     *
     * @return properties
     */
    public static Properties getConfig() {
        String location = " - getConfig() - ";
        if ( PROPERTIES == null ) {
            logger.debug( location + " creating configuration " + CONFIG_FILE);
            InputStream is = ConfigurationUtils.class.getResourceAsStream(CONFIG_FILE);
            PROPERTIES = new Properties();
            try {
                logger.debug(location + "loading configuration");
                PROPERTIES.load(is);
                logger.debug( location + "successfully loaded configuration");
            } catch ( IOException ioe ) {
                logger.error(location + "loading configuration error " + ioe.getMessage() );
            } // end if
        } // end if

        return PROPERTIES;
    } // end of getConfig()


    /**
     * Get config property value.
     *
     * @param key   key
     * @return      value
     */
    public static String get(String key) {
        return getConfig().getProperty( key );
    }
}
